package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.extension.BaseFormInfo;
import com.alpha.eceasy.mall.api.dto.ShoppingCartDTO;
import com.alpha.eceasy.mall.api.entity.MallShoppingCart;
import com.alpha.eceasy.mall.api.vo.MallShoppingCartVO;
import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.service.MallShoppingCartService;
import com.alpha.eceasy.mall.service.impl.MallShoppingCartServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 购物车
 *
 * @author huangpengfei
 */
@RestController
@RequestMapping("/shopping-cart")
@Tag(description = "shopping-cart", name = "购物车")
public class MallShoppingCartController {
    @Resource
    private MallShoppingCartServiceImpl mallShoppingCartService;

    /**
     * 分页查询
     *
     * @param mallShoppingCart 购物车
     * @return 分页结果
     */
    @Operation(description = "分页查询", summary = "分页查询")
    @GetMapping("")
    public R<IPage<MallShoppingCart>> getMallShoppingCartPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNumber,
                                                              @RequestParam(value = "pageSize", required = false, defaultValue = "1000") Integer pageSize,
                                                              MallShoppingCart mallShoppingCart) {
        return R.ok(mallShoppingCartService.page(Page.of(pageNumber, pageSize), Wrappers.lambdaQuery(mallShoppingCart)
                .eq(BaseFormInfo::getDeleted, false)));
    }

    /**
     * 新增购物车
     *
     * @param mallShoppingCart 购物车
     * @return R 返回结果 购物车信息
     */
    @Operation(description = "新增购物车", summary = "新增购物车")
//	@SysLog("新增购物车")
    @PostMapping
    public R<MallShoppingCartVO> saveCat(@RequestBody MallShoppingCart mallShoppingCart) {
        return R.ok(mallShoppingCartService.saveCat(mallShoppingCart));
    }

    /**
     * 通过guid修改购物车
     *
     * @param mallShoppingCart 购物车
     * @return R 返回结果 购物车信息
     */
    @Operation(description = "通过guid修改购物车", summary = "通过guid修改购物车")
//	@SysLog("修改购物车")
    @PutMapping
    public R<MallShoppingCart> updateByGuid(@RequestBody MallShoppingCart mallShoppingCart) {
        return R.ok(mallShoppingCartService.updateShoppingCartByGuid(mallShoppingCart));
    }

    /**
     * 通过guidList删除购物车
     *
     * @param dto guids
     * @return R 返回结果 是否成功
     */
    @Operation(description = "通过guidList删除购物车", summary = "通过guidList删除购物车")
//	@SysLog("通过guid删除购物车")
    @DeleteMapping("")
    public R<Boolean> removeByGuids(@RequestBody ShoppingCartDTO dto) {
        return R.ok(mallShoppingCartService.removeByGuidList(dto));
    }

    @GetMapping(value = "/selectListByCustomerGuid")
    @Operation(description = "查看当前登录用户购物车列表", summary = "查看当前登录用户购物车列表")
    public R<List<MallShoppingCartVO>> selectListByCustomerGuid() {
        return R.ok(mallShoppingCartService.selectListByCustomerGuid());
    }

    @Operation(description = "购物车清空", summary = "购物车清空")
//	@SysLog("购物车清空")
    @DeleteMapping("/customerId")
    public R<Boolean> removeByCustomerId() {
        return R.ok(mallShoppingCartService.removeByCustomerId());
    }

}
